﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_BLL;
using CoolERP_Entities;

namespace CoolERP_Web.User
{
    [PermissionCheck(false)]
    public partial class SelectHT : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindFirst();
                BindData();
            }
        }

        private void BindFirst()
        {
            this.AspNetPager1.PageSize = GridView1.PageSize;
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }

        private void BindData()
        {
            Dictionary<string, string> dc = new Dictionary<string, string>();
            dc.Add("HTZT", "1");
            if (!string.IsNullOrEmpty(txtBH.Text.Trim()))
                dc.Add("BH", txtBH.Text.Trim());
            if (!string.IsNullOrEmpty(txtName.Text.Trim()))
                dc.Add("KHMC", txtName.Text.Trim());
            using (XSHTBLL xBLL = new XSHTBLL())
            {
                int RecordCount = 0;
                List<vXSHT> itemLists = xBLL.GetXSHT(dc, "BH", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out RecordCount);
                this.AspNetPager1.RecordCount = RecordCount;
                GridView1.DataSource = itemLists;
                GridView1.DataBind();
                this.AspNetPager1.Visible = RecordCount > 0;
                panMsg.Visible = !this.AspNetPager1.Visible;
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
    }
}